<?php
class isp_customer_invoice_model extends MY_Model {
	var $model = 'isp_customer_invoice';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	
					id_invoice,
					input_ppn,
					id_kontrak,
					kode_kontrak,
					kode_customer,
					nama_customer,
					abodemen,
					total,
					ppn,
					no_invoice,
					TO_CHAR(tanggal_invoice,'DD/MM/YYYY') tanggal_invoice,
					status,
					TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
					periode_tagihan,
					keterangan,
					biaya_pendaftaran,
					terbilang,
					TO_CHAR(due_date,'DD/MM/YYYY') due_date,
					nama_jenis_barang,
					bandwidth
					FROM	ISP_CLIENT_INVOICE
					WHERE	(UPPER(no_invoice) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kode_kontrak) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'no_invoice' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetJSON2()
	{
		$ls_sql	= "	SELECT	*
					FROM	isp_client_kontrak
					WHERE	(UPPER(kode_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(kode_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(harga) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_kontrak' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert('isp_client_invoice', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_client_invoice', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_id_invoice){
		$result = $this->db->get_where('isp_client_invoice', array('id_invoice' => $as_id_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_invoice)
	{
		$result = $this->db->get_where('isp_client_invoice', array('id_invoice' => $as_id_invoice));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM isp_client_invoice WHERE id_invoice = '".$arr_rule['id_invoice']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['id_invoice']."]<br />";
			}else{
				$this->db->delete('isp_client_invoice', array('id_invoice' => $arr_rule['id_invoice']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>